package org.je.util;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class WrappedBlockingQueue<T>
{
	private BlockingQueue<T>	qu;

	public WrappedBlockingQueue() {
		this(-1);
	}

	/**
	 * @param size
	 */
	public WrappedBlockingQueue(int size) {
		if (size > 0) {
			qu = new ArrayBlockingQueue<T>(size);
		} else {
			qu = new LinkedBlockingQueue<T>();
		}
	}

	public T take() {
		try {
			return qu.take();
		} catch (InterruptedException e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * @param t
	 */
	public void put(T t) {
		try {
			qu.put(t);
		} catch (InterruptedException e) {
			throw new RuntimeException(e);
		}
	}

	public int size() {
		return qu.size();
	}
}
